package com.mostka.client;

import com.google.gwt.core.client.EntryPoint;
import com.mostka.ws.client.ConnectionHandler;
import com.mostka.ws.client.JsCloseEvent;
import com.mostka.ws.client.JsErrorEvent;
import com.mostka.ws.client.JsMessageEvent;
import com.mostka.ws.client.JsOpenedEvent;
import com.mostka.ws.client.WebSocket;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class WebSocketTest implements EntryPoint {

	public static native void log(Object obj) /*-{
		console.log(obj);
	}-*/;
	
	public void onModuleLoad() {
		WebSocket ws = new WebSocket("testChannel");
		ws.setHandler(new ConnectionHandler() {
			
			@Override
			public void onOpen(JsOpenedEvent openEvent) {
				log("opened");
			}
			
			@Override
			public void onMessage(JsMessageEvent mesageEvent) {
				log("message:"+mesageEvent.getData());
			}
			
			@Override
			public void onError(JsErrorEvent errorEvent) {
				log("error");
				log(errorEvent);
			}
			
			@Override
			public void onClose(JsCloseEvent closeEvent) {
				log("closed");
			}
		});
	}

}
